<?php

declare(strict_types=1);

namespace App\Jobs\Sms;

use App\Services\SmsVerifyCodeService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class VerifyCodeJob implements ShouldQueue
{
    use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels;

    /**
     * @var string
     */
    private $phone;

    /**
     * @var string
     */
    private $code;

    /**
     * VerifyCodeJob constructor.
     */
    public function __construct(string $phone, string $code)
    {
        $this->phone = $phone;
        $this->code  = $code;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try {
            SmsVerifyCodeService::sendSMS($this->phone, $this->code);
        } catch (\Throwable $e) {
            logException($e);
        }
    }
}
